//package spring2012source;

/**
 * @author ITEC 3150
 * @version 1.0
 * Purpose of program: Draws a window using AWT 
 **/


import java.awt.*;
import java.awt.event.*;

public class DrawableFrame extends Frame {

	private  Image imageBuffer = null;
	private Insets insets;
	private static final long serialVersionUID = -7655220196707375886L;

	//private serialVersionUID = 1;


	/**
	 * Constructor
	 * @param title
	 */
	public DrawableFrame(String title) {
		super(title);
		addWindowListener(new WindowCloser());
	}

	// Called automatically to display the contents of the
	// frame
	public void paint(Graphics g) {
		if (imageBuffer != null)
			g.drawImage(imageBuffer, insets.left, insets.top, null);
	}

	// Called automatically by repaint. Used to reduce flicker.
	public void update(Graphics g) {
		paint(g);
	}

	// Sets the size of the frame. The width and height
	// parameters control the size of the drawable portion of
	// the frame. The frame itself is somewhat larger.
	public void setSize(int width, int height) {
		insets = getInsets();
		super.setSize(width + insets.left + insets.right,
				height + insets.top + insets.bottom);
		imageBuffer = createImage(width, height);
	}

	// Returns the graphics context associated with the image
	// buffer
	public Graphics getGraphicsContext() {
		return imageBuffer.getGraphics();
	}

	// Listener for window
	public class WindowCloser extends WindowAdapter {
		public void windowClosing(WindowEvent evt) {
			System.exit(0);
		}
	}
}